/**
 * 
 * 广州锐鹏计算机科技有限公司（www.ruipengkj.com）
 * 
 * 
 * Copyright (c) 2011-2012 RUIPENGKJ.Co.Ltd. All rights reserved.
 * 
 * */
package com.ruipengkj.component.jpanel;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.LayoutManager;
import java.awt.TexturePaint;

import javax.swing.JPanel;

import com.ruipengkj.commons.util.Util;
import com.ruipengkj.factory.ImageFactory;
import com.ruipengkj.factory.UIFactory;
/**
 * 说明：
 * 以图片做背景的面板
 */
public class RPJPanelStatementTop extends JPanel {

	private static final long serialVersionUID = 1L;

	private MianPanel mainPanel;
	
	public RPJPanelStatementTop() {
		super(new BorderLayout());
		mainPanel = new MianPanel(new FlowLayout(FlowLayout.CENTER));
		JPanel jp = UIFactory.getInstance().createFlowJPanel();
		
		Util.setSize(mainPanel, 0, 46);
		Util.setSize(jp, 4, 4);
		
		super.add(mainPanel);
		super.add(jp, BorderLayout.NORTH);
		super.add(UIFactory.getInstance().createFlowJPanel(), BorderLayout.WEST);
		super.add(UIFactory.getInstance().createFlowJPanel(), BorderLayout.EAST);
		this.setBackground(new Color(247, 252, 255));
	}

	@Override
	public Component add(Component comp) {
		return mainPanel.add(comp);
	}
	
	class MianPanel extends JPanel {
		private static final long serialVersionUID = 1L;
		private TexturePaint paint = Util.createTexturePaint(ImageFactory.loadImage(ImageFactory.PANEL_STATEMENT_TOP_BG).getImage());
		private Image backgroundLeftImage = ImageFactory.loadImage(ImageFactory.PANEL_STATEMENT_TOP_BG_LEFT).getImage();
		private Image backgroundRightImage = ImageFactory.loadImage(ImageFactory.PANEL_STATEMENT_TOP_BG_RIGHT).getImage();
		
		public MianPanel() {}
		public MianPanel(LayoutManager layout) {
			super(layout);
		}
		@Override
		protected void paintComponent(Graphics g) {
			super.paintComponent(g);
			Graphics2D g2d = (Graphics2D) g;
			g2d.drawImage(backgroundLeftImage, 0, 0, null);
			g2d.setPaint(paint);
			int x = backgroundLeftImage.getWidth(null); 
			int width = getWidth() - x - backgroundRightImage.getWidth(null);
			int height = getHeight();
			g2d.fillRect(x, 0, width, height);
			g2d.drawImage(backgroundRightImage, x + width, 0, null);
		}
		
		@Override
		protected void paintBorder(Graphics g) {
			g.setColor(new Color(247, 252, 255));
			g.fillRect(0, 43, this.getWidth(), 3);
		}
	}
}
